package org.lazycoder.logger;

import java.util.Date;

/**
 * The base class for EventLogger Modules. Overload this and call notify(Event
 * e) when you want something logging to the database.
 * 
 * This class also implements runnable so overload run() if you want your class
 * to work in the background.
 * 
 * @author Matthew Bayliss
 * 
 */
public abstract class Module implements Runnable {

	/**
	 * Create the module and add it to the database.
	 */
	public Module() {
		EventLogger.getInstance().register(this);
		String text = "Module " +getName()+" is now active. ";
		Event event = new Event(text, new Date());
		notify(event);
	}

	/**
	 * @return name of the current module.
	 */
	public abstract String getName();

	@Override
	public void run() {

	}

	/**
	 * Notify the event logger that something has happened.
	 * 
	 * @param e
	 *            The event that has occurred.
	 */
	protected void notify(Event e) {
		EventLogger.getInstance().update(this, e);
	}
	
	/**
	 * Override this method to implement something to stop running threads
	 */
	public void stop(){
	}

}
